package com.example.commonmybatisplus.utils.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.springframework.stereotype.Component;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/5/30 11:12
 * @Version 1.0.0
 * @Description
 **/
@Component
public class Define2SqlInjector extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        String sql = "insert into " + tableInfo.getTableName() + " values(null,'harry',2,16)";
        /* mapper 接口方法名一致 */
        String method = "addBackDoor";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);

        return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
    }
}
